package demo2;

import java.util.Objects;

class Person{
    public String name;

    public Person(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return Objects.equals(name, person.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }
}

public class Test {
    public static void main(String[] args) {
        Person person1=new Person("zhangsan");
        Person person2=new Person("zhangsan");
        System.out.println(person1==person2);
        System.out.println(person1.name.equals(person2.name));
        System.out.println(person1.name.hashCode());
        System.out.println(person2.name.hashCode());
    }
}
